package com.dev.op.service;

import com.dev.op.entity.Problem;
import jakarta.annotation.PostConstruct;
import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DataPreHeat {
    @Autowired
    private ProblemService problemService;

    @Autowired
    private RBloomFilter<String> problemIdBloomFilter;

    @PostConstruct
    public void preheatData() {
        // 查询数据库中的所有问题 ID，进行布隆过滤器预热
        List<Problem> problemList = problemService.list();
        for(Problem problem : problemList) {
            problemIdBloomFilter.add(String.valueOf(problem.getProblemId()));
        }
        System.out.println("Data preheat completed!");
    }
}
